import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNumber, IsDate, IsOptional, IsISBN, Min } from 'class-validator';
import { Type } from 'class-transformer';

export class UpdateBookDto {
  @ApiProperty({ description: '书名', example: '深入理解TypeScript', required: false })
  @IsOptional()
  @IsString({ message: '书名必须是字符串' })
  title?: string;

  @ApiProperty({ description: '作者', example: '张三', required: false })
  @IsOptional()
  @IsString({ message: '作者必须是字符串' })
  author?: string;

  @ApiProperty({ description: '出版社', example: '人民邮电出版社', required: false })
  @IsOptional()
  @IsString({ message: '出版社必须是字符串' })
  publisher?: string;

  @ApiProperty({ description: '出版日期', example: '2023-01-01', required: false })
  @IsOptional()
  @Type(() => Date)
  @IsDate({ message: '出版日期格式不正确' })
  publishDate?: Date;

  @ApiProperty({ description: 'ISBN', example: '978-7-115-54721-5', required: false })
  @IsOptional()
  @IsISBN(undefined, { message: 'ISBN格式不正确' })
  isbn?: string;

  @ApiProperty({ description: '价格', example: 89.00, required: false })
  @IsOptional()
  @IsNumber({}, { message: '价格必须是数字' })
  @Min(0, { message: '价格不能小于0' })
  price?: number;

  @ApiProperty({ description: '库存数量', example: 100, required: false })
  @IsOptional()
  @IsNumber({}, { message: '库存数量必须是数字' })
  @Min(0, { message: '库存数量不能小于0' })
  stock?: number;

  @ApiProperty({ description: '图书简介', example: '这是一本关于TypeScript的书籍', required: false })
  @IsOptional()
  @IsString({ message: '图书简介必须是字符串' })
  description?: string;
}